<!DOCTYPE html>












  


<html class="theme-next gemini use-motion" lang="en">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">


























<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2">

<link rel="stylesheet" href="/css/main.css?v=7.0.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.0.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32.ico?v=7.0.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16.ico?v=7.0.0">


  <link rel="mask-icon" href="/images/logo.svg?v=7.0.0" color="#222">







<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '7.0.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="web 项目访问静态资源这项技能是必备的好嘛，而今我们来排一排 SpringBoot 项目访问静态资源中的坑。">
<meta name="keywords" content="JavaWeb,SpringBoot,thymeleaf,HTML,静态资源访问">
<meta property="og:type" content="article">
<meta property="og:title" content="SpringBoot项目访问静态资源">
<meta property="og:url" content="https://blog-test.jetchen.cn/springboot-staticfiles/index.html">
<meta property="og:site_name" content="嘎里三分熟">
<meta property="og:description" content="web 项目访问静态资源这项技能是必备的好嘛，而今我们来排一排 SpringBoot 项目访问静态资源中的坑。">
<meta property="og:locale" content="en">
<meta property="og:image" content="http://blogsource.chenkaikai.com/uploads/image/20170708/1499506625290109.png">
<meta property="og:image" content="http://blogsource.chenkaikai.com/uploads/image/20170708/1499506625610648.png">
<meta property="og:image" content="http://blogsource.chenkaikai.com/uploads/image/20170708/1499506664421139.png">
<meta property="og:image" content="http://blogsource.chenkaikai.com/uploads/image/20170708/1499507116527284.png">
<meta property="og:image" content="http://blogsource.chenkaikai.com/uploads/image/20170708/1499507806499804.png">
<meta property="og:image" content="http://blogsource.chenkaikai.com/uploads/image/20170708/1499511341830749.png">
<meta property="og:image" content="http://blogsource.chenkaikai.com/uploads/image/20170708/1499510164796785.png">
<meta property="og:image" content="http://blogsource.chenkaikai.com/uploads/image/20170708/1499510986494615.png">
<meta property="og:image" content="http://blogsource.chenkaikai.com/uploads/image/20170708/1499510492591080.png">
<meta property="og:image" content="http://blogsource.chenkaikai.com/uploads/image/20170708/1499510492978632.png">
<meta property="og:updated_time" content="2019-02-25T15:35:28.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="SpringBoot项目访问静态资源">
<meta name="twitter:description" content="web 项目访问静态资源这项技能是必备的好嘛，而今我们来排一排 SpringBoot 项目访问静态资源中的坑。">
<meta name="twitter:image" content="http://blogsource.chenkaikai.com/uploads/image/20170708/1499506625290109.png">






  <link rel="canonical" href="https://blog-test.jetchen.cn/springboot-staticfiles/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>SpringBoot项目访问静态资源 | 嘎里三分熟</title>
  












  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="en">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">嘎里三分熟</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="Toggle navigation bar">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
    
      
    

    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>Home</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-about">

    
    
    
      
    

    

    <a href="/about-me/" rel="section"><i class="menu-item-icon fa fa-fw fa-user"></i> <br>About</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
    
      
    

    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>Archives</a>

  </li>

      
      
    </ul>
  

  

  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://blog-test.jetchen.cn/springboot-staticfiles/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Jet Chen">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="嘎里三分熟">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">SpringBoot项目访问静态资源

              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              

              
                
              

              <time title="Created: 2017-07-08 18:59:12" itemprop="dateCreated datePublished" datetime="2017-07-08T18:59:12+08:00">2017-07-08</time>
            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/SpringBoot/" itemprop="url" rel="index"><span itemprop="name">SpringBoot</span></a></span>

                
                
              
            </span>
          

          
            
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><center>web 项目访问静态资源这项技能是必备的好嘛，而今我们来排一排 SpringBoot 项目访问静态资源中的坑。</center><br><a id="more"></a></p>
<h2>一、目的说明<br></h2>

<p>先说源码：<a href="https://github.com/goldenJet/POIDemo.git" target="_blank" rel="noopener">https://github.com/goldenJet/POIDemo.git</a></p>
<p>如下是我们的 resources 结构和 controller 实现，目的是通过 <a href="http://localhost:8081/home" target="_blank" rel="noopener">http://localhost:8081/home</a>&nbsp;这个路径来访问我们指定在 templetes 文件夹下的 index.html。</p>
<p><img src="http://blogsource.chenkaikai.com/uploads/image/20170708/1499506625290109.png" title="1499506625290109.png">&nbsp; &nbsp; &nbsp;&nbsp;<img src="http://blogsource.chenkaikai.com/uploads/image/20170708/1499506625610648.png" title="1499506625610648.png"></p>
<p>但是事实是，给我们返回的是 404，很伤心。</p>
<p><img src="http://blogsource.chenkaikai.com/uploads/image/20170708/1499506664421139.png" title="1499506664421139.png" alt="html03.png"></p><p></p>
<h2>二、方法一：使用模板引擎实现</h2>

<p>Java 的 web 项目，我们常用一些前端的模板引擎，比如 SpringBoot 已经自支持的 Thymeleaf 和 FreeMaker 等。<br></p>
<p>比如以&nbsp;<span style="font-size: 14px;">Thymeleaf 为例，我们需要引入他的包，如下。</span></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependency&gt;</span><br><span class="line">&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;</span><br><span class="line">&lt;/dependency&gt;</span><br></pre></td></tr></table></figure>
<p>然后修改 controller 中返回的页面名称，<br></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">@RequestMapping(&quot;/home&quot;)</span><br><span class="line">public&amp;nbsp;String&amp;nbsp;home()&#123;</span><br><span class="line">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;&quot;index&quot;;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>重启项目，然后便能正常访问了，<br></p>
<p><img src="http://blogsource.chenkaikai.com/uploads/image/20170708/1499507116527284.png" title="1499507116527284.png" alt="html04.png"></p>
<p>是不是很神奇，其实很简单，就是&nbsp;Thymeleaf 会根据我们返回的页面名字（此处是“index”），自动去 templates 文件夹下去查找有没有对应的 index.html 模板，然后进行渲染返回给我们，因为默认配置的是去 templates 文件夹下查找 .html 结尾的模板。具体配置参数可见&nbsp;<strong>ThymeleafProperties </strong>这个类，下图是部分源码截图，<br></p>
<p><img src="http://blogsource.chenkaikai.com/uploads/image/20170708/1499507806499804.png" title="1499507806499804.png" alt="html05.png"></p>
<p>当然，如果想覆盖掉默认的配置，只需要去&nbsp;application.properties 配置文件中 覆盖掉对应的参数即可，如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">server.port=8081</span><br><span class="line">#&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&amp;nbsp;thymeleaf&amp;nbsp;配置</span><br><span class="line">#&amp;nbsp;推荐配置项</span><br><span class="line">#&amp;nbsp;缓存关闭（即每次渲染都会去重新请求服务器）</span><br><span class="line">spring.thymeleaf.cache=false</span><br><span class="line">#&amp;nbsp;随意一点，默认的挺好</span><br><span class="line">#&amp;nbsp;模板所在位置</span><br><span class="line">spring.thymeleaf.prefix=classpath:/templates/</span><br><span class="line">#&amp;nbsp;模板后缀</span><br><span class="line">spring.thymeleaf.suffix=.html</span><br><span class="line">#&amp;nbsp;不解释</span><br><span class="line">spring.thymeleaf.content-type=text/html</span><br><span class="line">spring.thymeleaf.encoding=UTF-8</span><br><span class="line">spring.thymeleaf.mode=HTML5</span><br><span class="line">#&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&amp;nbsp;end</span><br></pre></td></tr></table></figure>
<h2>三、方法二：改变资源映射来实现</h2>

<p>我们把 pom.xml 中的 thymeleaf 的包注掉，然后修改 controller 中的相关代码，直接返回 index.html，显然此时是无法访问的，</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">@Controller</span><br><span class="line">public&amp;nbsp;class&amp;nbsp;Home&amp;nbsp;&#123;</span><br><span class="line">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@RequestMapping(&quot;/home&quot;)</span><br><span class="line">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;String&amp;nbsp;home()&#123;</span><br><span class="line">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;&quot;index.html&quot;;</span><br><span class="line">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>怎么办呢，既然它找不到我们的文件路劲，那么我们就给他指条明路不就好了，</p>
<p>所以我们指定资源的映射，写一个配置类不就OK了，这个类需要继承&nbsp;<strong>WebMvcConfigurerAdapter</strong>，然后复写其中的 <strong>addResourceHandlers</strong>&nbsp;方法就好，如下例：<br></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">@Configuration</span><br><span class="line">public&amp;nbsp;class&amp;nbsp;MvcConfigurer&amp;nbsp;extends&amp;nbsp;WebMvcConfigurerAdapter&amp;nbsp;&#123;</span><br><span class="line">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/**</span><br><span class="line">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&amp;nbsp;配置静态资源访问</span><br><span class="line">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*&amp;nbsp;@param&amp;nbsp;registry</span><br><span class="line">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*/</span><br><span class="line">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Override</span><br><span class="line">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;addResourceHandlers(ResourceHandlerRegistry&amp;nbsp;registry)&amp;nbsp;&#123;</span><br><span class="line">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;将资源路径映射到指定的classpath</span><br><span class="line">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;registry.addResourceHandler(&quot;/**&quot;).addResourceLocations(&quot;classpath:/templates/&quot;);</span><br><span class="line">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;super.addResourceHandlers(registry);</span><br><span class="line">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>此处我们是将所有的访问路径，即“/**”映射到 templates 文件夹下，你也可以根据自己的需求来具体配置，<br></p>
<p>然后访问&nbsp;<a href="http://localhost:8081/home" target="_blank" rel="noopener">http://localhost:8081/home</a>&nbsp;又能愉快地玩耍了。</p>
<p>当然，资源路径还可以映射到本地，即映射到 D 盘之类的，如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">//&amp;nbsp;将资源路径映射到计算机本地&amp;nbsp;D&amp;nbsp;盘</span><br><span class="line">registry.addResourceHandler(&quot;/d/**&quot;).addResourceLocations(&quot;file:D:/&quot;);</span><br></pre></td></tr></table></figure>
<h2>四、进阶小篇（优先级的问题）</h2>

<p>其实，一个 web 项目，在classpath 目录下，一般会有以下几个常用的目录，</p>
<p>我们在里面都放了一个 index.html，body里面就一个p 标签，如下：<br></p>
<p><img src="http://blogsource.chenkaikai.com/uploads/image/20170708/1499511341830749.png" title="1499511341830749.png" alt="html06.png"></p>
<p>好，亮点来了，我们把资源路径的映射注掉，然后重启项目，仍旧访问&nbsp;<a href="http://localhost:8081/home，" target="_blank" rel="noopener">http://localhost:8081/home</a></p>
<p><img src="http://blogsource.chenkaikai.com/uploads/image/20170708/1499510164796785.png" title="1499510164796785.png" alt="html07.png"></p>
<p>嘿嘿，之前不能访问的，现在却能访问？其实玄机就是 web 项目，默认的 classpath 下的路径便是&nbsp;<strong>classpath:/META-INF/resources/</strong></p>
<p>当然，你再把这个目录下的 index.html 删掉，访问，</p>
<p><img src="http://blogsource.chenkaikai.com/uploads/image/20170708/1499510986494615.png" title="1499510986494615.png" alt="html10.png"></p>
<p>好吧，他还是找到了 resources 目录下，继续删，</p>
<p><img src="http://blogsource.chenkaikai.com/uploads/image/20170708/1499510492591080.png" title="1499510492591080.png"></p>
<p>好吧，他还会继续找到 static 目录下，继续删，</p>
<p><img src="http://blogsource.chenkaikai.com/uploads/image/20170708/1499510492978632.png" title="1499510492978632.png"></p>
<p>OK，接着会找到 public，再删，好吧，然后就 404 了，</p>
<p>所以，总结，这四个目录是默认的存储静态资源的路径，当然了，他们也是存在优先级的，如下，从左到右优先级依次降低：</p>
<p><span style="color: #FF0000;"><strong>/META-INF/resource</strong><strong>s</strong> &gt;&gt;&nbsp;<strong>/resources</strong> &gt;&gt;&nbsp;<strong>/static</strong> &gt;&gt;&nbsp;<strong>/public</strong></span></p>
<p><br></p>
<p><br></p>
<p><br></p>
<p><br></p>
<p><br></p>
<p><br></p>
<p><br></p>
<p><br></p>
<p><br></p>
<p><br></p>

      
    </div>

    

    
    
    
	
	<div>
	  
		<div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">------ 本文结束 <i class="fa fa-fighter-jet"></i> 感谢阅读 ------</div>
    
</div>
	  
	</div>

    

    
      
    
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/JavaWeb/" rel="tag"><i class="fa fa-tag"></i> JavaWeb</a>
          
            <a href="/tags/SpringBoot/" rel="tag"><i class="fa fa-tag"></i> SpringBoot</a>
          
            <a href="/tags/thymeleaf/" rel="tag"><i class="fa fa-tag"></i> thymeleaf</a>
          
            <a href="/tags/HTML/" rel="tag"><i class="fa fa-tag"></i> HTML</a>
          
            <a href="/tags/静态资源访问/" rel="tag"><i class="fa fa-tag"></i> 静态资源访问</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/linux-redis-install/" rel="next" title="Linux下安装Redis">
                <i class="fa fa-chevron-left"></i> Linux下安装Redis
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/bugfixed-unsupportedoperationexception/" rel="prev" title="Java异常之：UnsupportedOperationException">
                Java异常之：UnsupportedOperationException <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">Jet Chen</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">68</span>
                    <span class="site-state-item-name">posts</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">33</span>
                    <span class="site-state-item-name">categories</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">182</span>
                    <span class="site-state-item-name">tags</span>
                  </a>
                </div>
              
            </nav>
          

          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="https://github.com/goldenJet" title="GitHub &rarr; https://github.com/goldenJet" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="https://twitter.com/goldenJ51015801" title="Twitter &rarr; https://twitter.com/goldenJ51015801" rel="noopener" target="_blank"><i class="fa fa-fw fa-twitter"></i>Twitter</a>
                </span>
              
            </div>
          

          

          
          

          
            
          
          

        </div>
      </div>

      
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#undefined"><span class="nav-number">1.</span> <span class="nav-text">一、目的说明</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#undefined"><span class="nav-number">2.</span> <span class="nav-text">二、方法一：使用模板引擎实现</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#undefined"><span class="nav-number">3.</span> <span class="nav-text">三、方法二：改变资源映射来实现</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#undefined"><span class="nav-number">4.</span> <span class="nav-text">四、进阶小篇（优先级的问题）</span></a></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2017 – <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Jet Chen</span>

  

  
</div>









<div class="BbeiAn-info">
    <a target="_blank" href="http://www.miitbeian.gov.cn/" rel="nofollow">浙ICP备17005575号-1</a> <!--a标签中增加nofollow属性，避免爬虫出站。-->| 
	<a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=33010802009043" style="text-decoration:none;padding-left:17px;background:url(/images/icon-police.png) no-repeat left center" rel="nofollow">浙公网安备 33010802009043号</a>	  <!--这里将图标作为了背景，以使得能和后面的文字在同一行-->
</div>

        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

    

    
  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  <script src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>


  


  <script src="/js/src/utils.js?v=7.0.0"></script>

  <script src="/js/src/motion.js?v=7.0.0"></script>



  
  


  <script src="/js/src/affix.js?v=7.0.0"></script>

  <script src="/js/src/schemes/pisces.js?v=7.0.0"></script>




  
  <script src="/js/src/scrollspy.js?v=7.0.0"></script>
<script src="/js/src/post-details.js?v=7.0.0"></script>



  


  <script src="/js/src/bootstrap.js?v=7.0.0"></script>



  


  


  




  

  

  

  

  

  

  

  

  

  

  

  

  

</body>
</html>
